//
//  UIButton.swift
//  weibo 666
//
//  Created by mac on 15/11/6.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

extension UIButton {
    
    ///便利构造函数
    convenience init(imageName: String, backImageName: String){
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        
        sizeToFit()
    }
    
    /// 便利构造函数
    ///
    /// - parameter title:          title
    /// - parameter color:          color
    /// - parameter backImageName:  背景图像名称
    ///
    /// - returns: UIButton
    convenience init(title: String, color: UIColor, backImageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        
        sizeToFit()
    }
    convenience init(title: String, color: UIColor, imageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        
        setBackgroundImage(UIImage(named: imageName), forState: .Normal)
        sizeToFit()
    }
    convenience init(title: String, fontSize: CGFloat, color: UIColor, imageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setImage(UIImage(named: imageName), forState: .Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()
    }
    
    
}
